from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-05-09 14:02:08.649984
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 09, May, 2022
Time: 14:02:14
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.2269
Nobs: 651.000 HQIC: -49.6059
Log likelihood: 8001.32 FPE: 2.24985e-22
AIC: -49.8460 Det(Omega_mle): 1.96142e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.324353 0.061324 5.289 0.000
L1.Burgenland 0.105028 0.039083 2.687 0.007
L1.Kärnten -0.110048 0.020491 -5.371 0.000
L1.Niederösterreich 0.195687 0.081578 2.399 0.016
L1.Oberösterreich 0.119155 0.080549 1.479 0.139
L1.Salzburg 0.258169 0.041525 6.217 0.000
L1.Steiermark 0.044128 0.054531 0.809 0.418
L1.Tirol 0.105251 0.044017 2.391 0.017
L1.Vorarlberg -0.063389 0.038895 -1.630 0.103
L1.Wien 0.027402 0.071330 0.384 0.701
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.050930 0.131025 0.389 0.697
L1.Burgenland -0.032746 0.083505 -0.392 0.695
L1.Kärnten 0.040239 0.043780 0.919 0.358
L1.Niederösterreich -0.187976 0.174299 -1.078 0.281
L1.Oberösterreich 0.447479 0.172099 2.600 0.009
L1.Salzburg 0.285493 0.088721 3.218 0.001
L1.Steiermark 0.107494 0.116511 0.923 0.356
L1.Tirol 0.313591 0.094046 3.334 0.001
L1.Vorarlberg 0.021979 0.083103 0.264 0.791
L1.Wien -0.038201 0.152403 -0.251 0.802
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189262 0.031457 6.016 0.000
L1.Burgenland 0.090321 0.020048 4.505 0.000
L1.Kärnten -0.007804 0.010511 -0.742 0.458
L1.Niederösterreich 0.248055 0.041847 5.928 0.000
L1.Oberösterreich 0.156097 0.041319 3.778 0.000
L1.Salzburg 0.041244 0.021301 1.936 0.053
L1.Steiermark 0.025195 0.027973 0.901 0.368
L1.Tirol 0.086124 0.022579 3.814 0.000
L1.Vorarlberg 0.054814 0.019952 2.747 0.006
L1.Wien 0.118118 0.036590 3.228 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.112961 0.031559 3.579 0.000
L1.Burgenland 0.045573 0.020113 2.266 0.023
L1.Kärnten -0.014271 0.010545 -1.353 0.176
L1.Niederösterreich 0.180182 0.041982 4.292 0.000
L1.Oberösterreich 0.327603 0.041452 7.903 0.000
L1.Salzburg 0.101875 0.021369 4.767 0.000
L1.Steiermark 0.109816 0.028063 3.913 0.000
L1.Tirol 0.097707 0.022652 4.313 0.000
L1.Vorarlberg 0.059620 0.020016 2.979 0.003
L1.Wien -0.021785 0.036708 -0.593 0.553
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.114448 0.058801 1.946 0.052
L1.Burgenland -0.043289 0.037475 -1.155 0.248
L1.Kärnten -0.046379 0.019647 -2.361 0.018
L1.Niederösterreich 0.142963 0.078221 1.828 0.068
L1.Oberösterreich 0.158034 0.077234 2.046 0.041
L1.Salzburg 0.282944 0.039816 7.106 0.000
L1.Steiermark 0.055118 0.052287 1.054 0.292
L1.Tirol 0.166667 0.042206 3.949 0.000
L1.Vorarlberg 0.096410 0.037294 2.585 0.010
L1.Wien 0.075263 0.068395 1.100 0.271
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059555 0.046342 1.285 0.199
L1.Burgenland 0.031004 0.029535 1.050 0.294
L1.Kärnten 0.051551 0.015485 3.329 0.001
L1.Niederösterreich 0.204351 0.061647 3.315 0.001
L1.Oberösterreich 0.320910 0.060870 5.272 0.000
L1.Salzburg 0.040044 0.031380 1.276 0.202
L1.Steiermark 0.006640 0.041209 0.161 0.872
L1.Tirol 0.130137 0.033263 3.912 0.000
L1.Vorarlberg 0.065600 0.029392 2.232 0.026
L1.Wien 0.091005 0.053903 1.688 0.091
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.172800 0.055586 3.109 0.002
L1.Burgenland 0.005761 0.035426 0.163 0.871
L1.Kärnten -0.065106 0.018573 -3.505 0.000
L1.Niederösterreich -0.096897 0.073944 -1.310 0.190
L1.Oberösterreich 0.204899 0.073011 2.806 0.005
L1.Salzburg 0.054642 0.037639 1.452 0.147
L1.Steiermark 0.240072 0.049428 4.857 0.000
L1.Tirol 0.500631 0.039898 12.548 0.000
L1.Vorarlberg 0.059864 0.035255 1.698 0.090
L1.Wien -0.074246 0.064655 -1.148 0.251
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.147550 0.061678 2.392 0.017
L1.Burgenland 0.004856 0.039308 0.124 0.902
L1.Kärnten 0.060264 0.020609 2.924 0.003
L1.Niederösterreich 0.183146 0.082048 2.232 0.026
L1.Oberösterreich -0.059263 0.081013 -0.732 0.464
L1.Salzburg 0.206849 0.041764 4.953 0.000
L1.Steiermark 0.133343 0.054845 2.431 0.015
L1.Tirol 0.069997 0.044270 1.581 0.114
L1.Vorarlberg 0.143634 0.039119 3.672 0.000
L1.Wien 0.111441 0.071741 1.553 0.120
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.378292 0.036281 10.427 0.000
L1.Burgenland -0.001063 0.023123 -0.046 0.963
L1.Kärnten -0.021952 0.012123 -1.811 0.070
L1.Niederösterreich 0.211143 0.048264 4.375 0.000
L1.Oberösterreich 0.226095 0.047655 4.744 0.000
L1.Salzburg 0.039079 0.024567 1.591 0.112
L1.Steiermark -0.014159 0.032262 -0.439 0.661
L1.Tirol 0.095717 0.026042 3.675 0.000
L1.Vorarlberg 0.053624 0.023012 2.330 0.020
L1.Wien 0.035348 0.042201 0.838 0.402
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036099 0.113710 0.172675 0.141855 0.101448 0.084728 0.038925 0.209358
Kärnten 0.036099 1.000000 -0.021592 0.134255 0.052042 0.089982 0.441238 -0.060873 0.092771
Niederösterreich 0.113710 -0.021592 1.000000 0.321894 0.130658 0.284982 0.075467 0.161579 0.295166
Oberösterreich 0.172675 0.134255 0.321894 1.000000 0.220636 0.310051 0.168786 0.149225 0.249559
Salzburg 0.141855 0.052042 0.130658 0.220636 1.000000 0.130561 0.096867 0.114828 0.128850
Steiermark 0.101448 0.089982 0.284982 0.310051 0.130561 1.000000 0.138626 0.118597 0.050617
Tirol 0.084728 0.441238 0.075467 0.168786 0.096867 0.138626 1.000000 0.069663 0.147995
Vorarlberg 0.038925 -0.060873 0.161579 0.149225 0.114828 0.118597 0.069663 1.000000 0.006029
Wien 0.209358 0.092771 0.295166 0.249559 0.128850 0.050617 0.147995 0.006029 1.000000